package controller

import (
	"admin/contrib/session"
	"admin/contrib/validator"
	"admin/model"
	"common/helper"
	"encoding/json"
	g "github.com/doug-martin/goqu/v9"
	"github.com/valyala/fasthttp"
	"strconv"
	"strings"
	"time"
	"unicode/utf8"
)

type MemberController struct{}

type insertMemberParam struct {
	Username   string `json:"username"`    //注册账号
	ParentId   string `json:"parent_id"`   //上級 id
	Password   string `json:"password"`    //登录密碼
	Tester     int    `json:"tester"`      //1 正式账号 2 模拟账号 3代理
	OperatorId string `json:"operator_id"` //渠道id
	BusinessId string `json:"business_id"` //业务员id
}

type memberTestListParam struct {
	Uid        int    `json:"uid" cbor:"uid"`
	StartTime  string `json:"startTime" cbor:"start_time"`
	EndTime    string `json:"endTime" cbor:"end_time"`
	Page       int    `json:"page" cbor:"page"`
	PageSize   int    `json:"pageSize" cbor:"page_size"`
	OperatorId int    `json:"operator_id" cbor:"operator_id"`
	BusinessId int    `json:"business_id" cbor:"business_id"`
	RealName   string `json:"real_name" cbor:"real_name"`
}

type membetTestAddParam struct {
	Total      int     `json:"total" cbor:"total"`
	Amount     float64 `json:"Amount" cbor:"Amount"`
	Password   string  `json:"password"` //登录密碼
	Operatorid int     `json:"operatorid" cbor:"operatorid"`
	OperatorId string  `json:"operator_id" cbor:"operator_id"`
}

// 所有玩家
func (that *MemberController) List(ctx *fasthttp.RequestCtx) {
	param := model.MemberListParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	param.ExportExcel = ctx.QueryArgs().GetUintOrZero("export_excel")
	if param.ExportExcel == 1 {
		param.Page = 1
		param.PageSize = model.ExportExcelPageSize
	}
	if param.Page < 1 {
		param.Page = 1
	}

	//if param.PageSize < 10 || param.PageSize > 3000 {
	//	helper.RetData(ctx, false, "参数错误")
	//	return
	//}

	data, err := model.MemberList(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	if param.ExportExcel == 1 {
		_, exportData := model.MemberListOpt(data, param.ExportExcel)
		exportTitle := []string{
			"玩家ID",
			"归属渠道",
			"归属业务员",
			"玩家账号",
			"手机号",
			"总充值",
			"总提现",
			"账户余额",
		}
		filename := "所有玩家-" + time.Now().Format("20060102150405")
		if model.ExportExcel(filename, exportTitle, exportData) == nil {
			helper.RetData(ctx, true, filename)
		} else {
			helper.RetData(ctx, false, helper.RequestFail)
		}
		return
	} else {
		helper.RetData(ctx, true, data)
		return
	}
	//helper.RetData(ctx, true, data)
}

func (that *MemberController) Detail(ctx *fasthttp.RequestCtx) {
	param := model.MemberListParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {
		helper.RetData(ctx, false, "参数错误")
		return
	}
	data, err := model.MemberDetail(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, data)
}

// 游戏日志
func (that *MemberController) GameList(ctx *fasthttp.RequestCtx) {
	param := model.GameListParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	if param.Page < 1 {
		param.Page = 1
	}

	if param.PageSize < 10 || param.PageSize > 3000 {
		helper.RetData(ctx, false, "参数错误")
		return
	}

	data, err := model.GameRecord(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, data)
	return

}

// 游戏日志
func (that *MemberController) UserGameList(ctx *fasthttp.RequestCtx) {
	param := model.GameListParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	if param.Page < 1 {
		param.Page = 1
	}

	if param.PageSize < 10 || param.PageSize > 3000 {
		helper.RetData(ctx, false, "参数错误")
		return
	}

	data, err := model.UserGameRecord(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, data)
	return

}

// 金币日志
func (that *MemberController) CoinList(ctx *fasthttp.RequestCtx) {
	param := model.CoinListParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	param.ExportExcel = ctx.QueryArgs().GetUintOrZero("export_excel")
	if param.ExportExcel == 1 {
		param.Page = 1
		param.PageSize = model.ExportExcelPageSize
	}
	if param.Page < 1 {
		param.Page = 1
	}

	data, err := model.CoinRecord(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	data, exportData := model.CoinRecordListOpt(data, param.ExportExcel)

	if param.ExportExcel == 1 {
		exportTitle := []string{
			"玩家ID",
			"渠道ID",
			"房间ID",
			"初始金额",
			"类型",
			"金额",
			"当前余额",
			"税收",
			"时间",
		}
		filename := "金币日志-" + time.Now().Format("20060102150405")
		if model.ExportExcel(filename, exportTitle, exportData) == nil {
			helper.RetData(ctx, true, filename)
		} else {
			helper.RetData(ctx, false, helper.RequestFail)
		}

		return
	} else {
		helper.RetData(ctx, true, data)
		return
	}

}

// 会员配置新增
func (that MemberController) Insert(ctx *fasthttp.RequestCtx) {

	param := insertMemberParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	if !validator.CtypeDigit(param.Username) && !strings.Contains(param.Username, "@") {
		helper.RetData(ctx, false, helper.UsernameErr)
		return
	}
	if param.ParentId != "" && !validator.CtypeDigit(param.ParentId) {
		helper.RetData(ctx, false, helper.ParentAgencyCanNotUse)
		return
	}

	if param.Tester < 0 || param.Tester > 4 {
		helper.RetData(ctx, false, "参数错误")
		return
	}
	prefix := string(ctx.Request.Header.Peek("X-Prefix"))
	err = model.MemberInsert(param.Username, param.Password, param.ParentId, param.OperatorId, param.BusinessId, param.Tester, prefix)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, "成功")
}

type updateMemberBonusParam struct {
	Uid      string `json:"uid"`
	CanBonus int    `json:"can_bonus"`
}

func (that MemberController) UpdateMemberBonus(ctx *fasthttp.RequestCtx) {

	param := updateMemberBonusParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	if !validator.CtypeDigit(param.Uid) {
		helper.RetData(ctx, false, helper.UIDErr)
		return
	}
	if param.CanBonus != 1 && param.CanBonus != 2 {
		helper.RetData(ctx, false, "状态错误")
		return
	}

	err = model.MemberUpdateBonus(param.Uid, param.CanBonus)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, "成功")
}

type updateMemberBlogerParam struct {
	Uid      string `json:"uid"`
	IsBloger int    `json:"is_bloger"`
}

func (that MemberController) UpdateMemberBloger(ctx *fasthttp.RequestCtx) {

	param := updateMemberBlogerParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	if !validator.CtypeDigit(param.Uid) {
		helper.RetData(ctx, false, helper.UIDErr)
		return
	}
	if param.IsBloger != 1 && param.IsBloger != 0 {
		helper.RetData(ctx, false, "状态错误")
		return
	}

	err = model.MemberUpdateBloger(param.Uid, param.IsBloger)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, "成功")
}

type updateMemberPasswordParam struct {
	Uid      string `json:"uid"`
	Password string `json:"password"`
}

func (that MemberController) UpdateMemberPassword(ctx *fasthttp.RequestCtx) {

	param := updateMemberPasswordParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	if !validator.CtypeDigit(param.Uid) {
		helper.RetData(ctx, false, helper.UIDErr)
		return
	}

	err = model.MemberUpdatePassword(param.Uid, param.Password)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, "成功")
}

type updateMemberRebateParam struct {
	Uid       string `json:"uid"`
	CanRebate int    `json:"can_rebate"`
}

func (that MemberController) UpdateMemberRebate(ctx *fasthttp.RequestCtx) {

	param := updateMemberRebateParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	if !validator.CtypeDigit(param.Uid) {
		helper.RetData(ctx, false, helper.UIDErr)
		return
	}
	if param.CanRebate != 1 && param.CanRebate != 2 {
		helper.RetData(ctx, false, "状态错误")
		return
	}

	err = model.MemberUpdateRebate(param.Uid, param.CanRebate)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, "成功")
}

type updateMemberStateParam struct {
	Uid    string `json:"uid"`
	State  int    `json:"state"`
	Remake string `json:"remake"`
}

func (that MemberController) UpdateMemberState(ctx *fasthttp.RequestCtx) {

	param := updateMemberStateParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	if !validator.CtypeDigit(param.Uid) {
		helper.RetData(ctx, false, helper.UIDErr)
		return
	}
	if param.State > 4 || param.State < 0 {
		helper.RetData(ctx, false, "状态错误")
		return
	}
	if utf8.RuneCountInString(param.Remake) > 100 {
		helper.RetData(ctx, false, "参数错误")
		return
	}

	err = model.MemberUpdateState(param.Uid, param.State, param.Remake)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, "成功")
}

type updateMemberAgentChannelParam struct {
	Uid string `json:"uid"`
	Cid string `json:"cid"`
}

func (that MemberController) UpdateMemberAgentChannel(ctx *fasthttp.RequestCtx) {

	param := updateMemberAgentChannelParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	if !validator.CtypeDigit(param.Uid) {
		helper.RetData(ctx, false, helper.UIDErr)
		return
	}

	err = model.MemberUpdateAgentChannel(param.Uid, param.Cid)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, "成功")
}

type UpdateMemberFlowMultipleParam struct {
	Uid              string `json:"uid"`
	WinFlowMultiple  string `json:"win_flow_multiple"`
	LoseFlowMultiple string `json:"lose_flow_multiple"`
}

func (that MemberController) UpdateMemberFlowMultiple(ctx *fasthttp.RequestCtx) {

	param := UpdateMemberFlowMultipleParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	if !validator.CtypeDigit(param.Uid) {
		helper.RetData(ctx, false, helper.UIDErr)
		return
	}

	err = model.MemberUpdateFlowMultiple(param.Uid, param.WinFlowMultiple, param.LoseFlowMultiple)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, "成功")
}

type addMemberBonusParam struct {
	Uid      string `json:"uid"`
	Username string `json:"username"`
	Amount   string `json:"amount"`
}

func (that MemberController) AddMemberBonus(ctx *fasthttp.RequestCtx) {
	param := addMemberBonusParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	if !validator.CtypeDigit(param.Uid) {
		helper.RetData(ctx, false, helper.UIDErr)
		return
	}

	err = model.MemberAddBonus(param.Uid, param.Username, param.Amount)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, "成功")
}

type addRewardAmount struct {
	Uid    string  `json:"uid"`
	Amount float64 `json:"amount"`
}

func (that MemberController) AddRewardAmount(ctx *fasthttp.RequestCtx) {
	param := addRewardAmount{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	if !validator.CtypeDigit(param.Uid) {
		helper.RetData(ctx, false, helper.UIDErr)
		return
	}

	err = model.MemberAddReward(param.Uid, param.Amount)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, "成功")
}

// 获取测试号列表
func (that MemberController) GetMemberTestList(ctx *fasthttp.RequestCtx) {
	param := memberTestListParam{}

	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	//admin := session.AdminGet(ctx)
	if param.Page < 1 {
		param.Page = 1
	}

	if param.PageSize < 10 || param.PageSize > 3000 {
		helper.RetData(ctx, false, "参数错误")
		return
	}

	ex := g.Ex{}

	if param.RealName != "" {
		member, _ := model.MemberFindByRealname(param.RealName)
		//fmt.Println(member)
		if member.Uid != "" {
			ex["uid"] = member.Uid
		} else {
			ex["uid"] = "0"
		}

	}
	if param.Uid > 0 {
		ex["uid"] = param.Uid
	}

	if param.OperatorId > 0 {
		ex["operator_id"] = param.OperatorId
	}

	data, err := model.MemberTestList(param.Page, param.PageSize, param.StartTime, param.EndTime, ctx, ex)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, data)
}

func (that MemberController) AddMemberTest(ctx *fasthttp.RequestCtx) {
	param := membetTestAddParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	if param.Total == 0 {
		helper.RetData(ctx, false, "参数错误")
		return
	}
	if param.Total > 1000 {
		helper.RetData(ctx, false, "一次性不能生成超过1000个测试号")
		return
	}
	err = model.NewMembetTestId(param.Amount, param.Total, param.Password, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, "成功")
}

type UpdateMemberTestPsw struct {
	Uid      string `json:"uid"`
	Password string `json:"password"`
}

// /修改密码
func (that MemberController) UpdateMemberTestPsw(ctx *fasthttp.RequestCtx) {
	param := UpdateMemberTestPsw{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	if !validator.CtypeDigit(param.Uid) {
		helper.RetData(ctx, false, helper.UIDErr)
		return
	}

	err = model.UpdateMemberTestPsw(param.Uid, param.Password)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, "成功")

}

func (that MemberController) MemberController(ctx *fasthttp.RequestCtx) {
	param := model.MemberControllerButton{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	userInfo, err := model.MemberFindByUid(strconv.Itoa(param.Uid))
	auth, err := model.UserAuthCheck(userInfo, ctx)
	if auth == false || err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	s, err := model.GetMemberController(param.Uid, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	s.SycDisbindLv1 = strings.Split(s.SycDisbindLv1, ",")[0]
	s.SycDisbindLv2 = strings.Split(s.SycDisbindLv2, ",")[0]
	s.SycDisbindLv3 = strings.Split(s.SycDisbindLv3, ",")[0]

	s.SycChargeHiddenLv1 = strings.Split(s.SycChargeHiddenLv1, ",")[0]
	s.SycChargeHiddenLv2 = strings.Split(s.SycChargeHiddenLv2, ",")[0]
	s.SycChargeHiddenLv3 = strings.Split(s.SycChargeHiddenLv3, ",")[0]
	helper.RetData(ctx, true, s)
}

func (that MemberController) UpdateMemberInfo(ctx *fasthttp.RequestCtx) {
	param := model.UpdateMemberParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	model.InsertLog("玩家信息编辑,更改密码，备注和状态，昵称", ctx)
	err = model.UpdateMemberInfo(param)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, "")
}

func (that MemberController) GetMemberRemarkLog(ctx *fasthttp.RequestCtx) {
	param := model.MemberLoginLogParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	s, err := model.GetMemberRemarkLog(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, s)
}

func (that MemberController) GetMemberChangeParentLog(ctx *fasthttp.RequestCtx) {
	param := model.MemberLoginLogParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	s, err := model.GetMemberChangeParentLog(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, s)
}

func (that MemberController) UpdateMemberController(ctx *fasthttp.RequestCtx) {

	param := model.UpdateMemberParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {
		helper.RetData(ctx, false, "参数错误")
		return
	}

	userInfo, err := model.MemberFindByUid(strconv.Itoa(int(param.Uid)))
	auth, err := model.UserAuthCheck(userInfo, ctx)
	if auth == false || err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	if param.Key == "rtp_control_way" || param.Key == "rtp" || param.Key == "fake_PP_rtp" || param.Key == "fake_JDB_rtp" || param.Key == "fake_JILI_rtp" {
		admin := session.AdminGet(ctx)
		if admin["loginuser"] == "merchant" {
			s := model.GameConfigByType(277)
			if s.CfgValue == "0" {
				helper.RetData(ctx, false, "无法设置玩家杀率，保存失败")
				return
			}

		}
		if admin["loginuser"] == "business" {
			s := model.GameConfigByType(278)
			if s.CfgValue == "0" {
				helper.RetData(ctx, false, "无法设置玩家杀率，保存失败")
				return
			}

		}
	}
	if param.Key == "unbind_button" || param.Key == "disbind_control" {
		admin := session.AdminGet(ctx)
		if admin["loginuser"] == "merchant" || admin["loginuser"] == "business" {
			s := model.GameConfigByType(276)
			if s.CfgValue == "1" {
				helper.RetData(ctx, false, "总台设置禁止掉绑")
				return
			}

		}
	}

	if param.Key == "syc_charge_hidden_lv1" || param.Key == "syc_charge_hidden_lv2" || param.Key == "syc_charge_hidden_lv3" || param.Key == "charge_hidden_button" || param.Key == "charge_hidden_control_f" || param.Key == "charge_hidden_control_s" || param.Key == "charge_hidden_button_f" || param.Key == "charge_hidden_button_s" {
		admin := session.AdminGet(ctx)
		if admin["loginuser"] == "merchant" {
			s := model.GameConfigByType(279)
			if s.CfgValue == "0" {
				helper.RetData(ctx, false, "总台设置禁止编辑，保存失败")
				return
			}

		}
		if admin["loginuser"] == "business" {
			s := model.GameConfigByType(280)
			if s.CfgValue == "0" {
				helper.RetData(ctx, false, "总台设置禁止编辑，保存失败")
				return
			}

		}
	}
	err = model.UpdateMemberController(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, "")
}

func (that MemberController) UpdateTeamMemberController(ctx *fasthttp.RequestCtx) {

	param := model.UpdateTeamMemberParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	//model.InsertLog("玩家团队控制信息编辑修改", ctx)

	userInfo, err := model.MemberFindByUid(strconv.Itoa(int(param.Uid)))
	auth, err := model.UserAuthCheck(userInfo, ctx)
	if auth == false || err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	if param.RtpControlWay != "" {
		admin := session.AdminGet(ctx)
		if admin["loginuser"] == "merchant" {
			s := model.GameConfigByType(277)
			if s.CfgValue == "0" {
				helper.RetData(ctx, false, "无法设置玩家杀率，保存失败")
				return
			}

		}
		if admin["loginuser"] == "business" {
			s := model.GameConfigByType(278)
			if s.CfgValue == "0" {
				helper.RetData(ctx, false, "无法设置玩家杀率，保存失败")
				return
			}

		}
	}
	err = model.UpdateTeamMemberController(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, "")
}

func (that MemberController) UpdateTeamReMemberController(ctx *fasthttp.RequestCtx) {

	param := model.UpdateTeamMemberParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	model.InsertLog("同步玩家"+strconv.Itoa(param.Uid)+"一级充值分成配置", ctx)

	userInfo, err := model.MemberFindByUid(strconv.Itoa(int(param.Uid)))
	auth, err := model.UserAuthCheck(userInfo, ctx)
	if auth == false || err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	err = model.UpdateTeamReMemberController(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, "")
}

func (that MemberController) UpdateTeamRemarkMemberController(ctx *fasthttp.RequestCtx) {

	param := model.UpdateMemberParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	model.InsertLog("玩家团队备注信息编辑修改", ctx)

	userInfo, err := model.MemberFindByUid(strconv.Itoa(int(param.Uid)))
	auth, err := model.UserAuthCheck(userInfo, ctx)
	if auth == false || err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	err = model.UpdateTeamRemarkMemberController(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, "")
}

// 登录日志
func (that MemberController) MemberLoginLog(ctx *fasthttp.RequestCtx) {
	param := model.MemberLoginLogParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	s, err := model.MemberLoginLog(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, s)
}

// 同ip查询
func (that MemberController) SameIpList(ctx *fasthttp.RequestCtx) {
	param := model.MemberListParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	s, err := model.SameIpList(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, s)
}

// 打码任务
func (that MemberController) WagRequire(ctx *fasthttp.RequestCtx) {
	param := model.WagRequireParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	s, err := model.GetWagRequire(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, s)
}

// 打码任务统计
func (that MemberController) WagRequireSummary(ctx *fasthttp.RequestCtx) {
	param := model.WagRequireParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	s, err := model.GetWagRequireSummary(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, s)
}

// 打码任务操作
func (that MemberController) WagRequireOpt(ctx *fasthttp.RequestCtx) {
	param := model.WagRequireOptParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	model.InsertLog("玩家打码量增加和减少", ctx)
	err = model.WagRequireOpt(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, "")
}

type PgResult struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data string `json:"data"`
}

func (that MemberController) GotoPg(ctx *fasthttp.RequestCtx) {
	uid := ctx.QueryArgs().GetUintOrZero("uid")
	if uid == 0 {
		helper.RetData(ctx, false, helper.IDErr)
		return
	}
	trasfer_url := model.GameConfigByType(3).CfgValue
	if trasfer_url == "" {
		helper.RetData(ctx, false, helper.URLErr)
		return
	}

	gameid, err := model.GetPgGameByRandom()
	if err != nil {
		helper.RetData(ctx, false, "数据库错误")
		return
	}
	//
	sign_str := strconv.Itoa(uid) + "9" + strconv.Itoa(gameid) + "1game_create_key_qwe123"
	sign_str = model.MD5(sign_str)
	trasfer_url += "/pggame/Index/createuser"
	postData := map[string]string{}
	postData["uid"] = strconv.Itoa(uid)
	postData["test"] = "1"
	postData["gameid"] = strconv.Itoa(gameid)
	postData["gtype"] = "9"
	postData["sign"] = sign_str

	headers := map[string]string{
		"Content-Type": "application/json;charset=utf-8",
	}
	requestParams, _ := helper.JsonMarshal(postData)
	statusCode, body, err := model.HttpPostHeader(requestParams, trasfer_url, headers)
	if err != nil {
		helper.RetData(ctx, false, helper.RequestFail)
		return
	}
	if statusCode != fasthttp.StatusOK {
		helper.RetData(ctx, false, helper.RequestFail)
		return
	}

	result_data := PgResult{}

	err = json.Unmarshal(body, &result_data)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	helper.RetData(ctx, true, result_data.Data)
	return
}
